var Hu = {};
Hu.Cookies = {
    set: function(b, c, a, d, e) {
        // (typeof a == "undefined" || a == '') && (a = new Date((new Date).getTime() + 31536E6));
        (typeof a == "undefined" || a == '') && (a = new Date((new Date).getTime() + 1800000));
        document.cookie = b + "=" + escape(c) + (a ? "; expires=" + a.toGMTString() : "") + (d ? "; path=" + d: "; path=/") + (e ? ";domain=" + e: "")
    },
    get: function(b) {
        b = document.cookie.match(RegExp("(^| )" + b + "=([^;]*)(;|$)"));
        if (b != null) return unescape(b[2]);
        return null
    },
    clear: function(b, c, a) {
        if (this.get(b)) document.cookie = b + "=" + (c ? "; path=" + c: "; path=/") + (a ? "; domain=" + a: "") + ";expires=Fri, 02-Jan-1970 00:00:00 GMT"
    }
}

function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return '';
}
function FillSelect(obj,data,isclear)
{
    var isclear = (arguments[2] == 0) ? 0 : 1;
    if(isclear == 1) $(obj).empty();
    $.each(data, function(key, val){
        $(obj).append('<option value="'+ key +'">'+ val +'</option>');
    })
}

function switchBlock(num, obj, current){
    var id = obj.id.replace(/^.+_/,"");
    var name_space = obj.id.replace(/_.+/,"");

    for(var i=1; i<=num; i++)
    {//判断是否有类 如果有就移除
		$('#'+name_space + "_nav_" + i).removeClass(current);
        $('#'+name_space + "_block_" + i).css('display','none');
    }
	$(obj.id).addClass(current);
    $('#'+name_space+"_block_"+id).css('display','block');
}

Date.prototype.format=function(fmt) {
    var o = {
    "M+" : this.getMonth()+1, //月份
    "d+" : this.getDate(), //日
    "h+" : this.getHours()%12 == 0 ? 12 : this.getHours()%12, //小时
    "H+" : this.getHours(), //小时
    "m+" : this.getMinutes(), //分
    "s+" : this.getSeconds(), //秒
    "q+" : Math.floor((this.getMonth()+3)/3), //季度
    "S" : this.getMilliseconds() //毫秒
    };
    var week = {
    "0" : "日",
    "1" : "一",
    "2" : "二",
    "3" : "三",
    "4" : "四",
    "5" : "五",
    "6" : "六"
    };
    if(/(y+)/.test(fmt)){
        fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
    }
    if(/(E+)/.test(fmt)){
        fmt=fmt.replace(RegExp.$1, ((RegExp.$1.length>1) ? (RegExp.$1.length>2 ? "星期" : "周") : "")+week[this.getDay()+""]);
    }
    for(var k in o){
        if(new RegExp("("+ k +")").test(fmt)){
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
        }
    }
    return fmt;
}

function changeFreeapi(currentPage, pageSize, list){
    var pageList = [];  //用于存储每一页的数组
    var num = list.length;  //参数数组长度
    var totalPage = 0;   //初始化总页数
    if(num/pageSize > parseInt(num/pageSize)) totalPage = parseInt(num/pageSize) + 1;  //totalPage有余数，再+1页显示
    else totalPage = parseInt(num/pageSize);    //totalPage没有余数，直接显示

    var maxLength = currentPage * pageSize - 1;  //最大长度   当前页最后一条的下标    29
    var minLength = currentPage * pageSize - pageSize;  //最大长度 当前页第一条的下标  15
    for (var i=minLength; i<list.length;i++){
        if(i>maxLength) break;   //遍历的下标 > 当前页最后一条的下标 退出循环
        else pageList.push(list[i]);
    }
    return pageList;   //制作成标签插入html中
}
